package com.lmabbe.tenant.objects.converter;

import com.lmabbe.tenant.objects.dto.SysDicDTO;
import com.lmabbe.tenant.objects.entity.SysDic;
import com.lmabbe.tenant.objects.vo.SysDicItemVO;
import com.lmabbe.tenant.objects.vo.SysDicTreeVo;
import com.lmabbe.tenant.objects.vo.SysDicVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;

/**
 * 系统字典表 转换器
 *
 * @author lmabbe
 */
@Mapper(componentModel = "spring")
public interface SysDicConverter {


    /**
     * dto转实体
     *
     * @param to
     * @return
     */
    SysDic dto2Entity(SysDicDTO to);

    /**
     * dto转实体
     *
     * @param to
     * @return
     */
    @Mapping(target = "dicId", source = "dicId")
    SysDic dto2Entity(SysDicDTO to, Long dicId);

    /**
     * 数据列表转Vo列表
     *
     * @param list
     * @return
     */
    List<SysDicVO> list2Vos(List<SysDic> list);

    /**
     * 实体转VO
     *
     * @param entity
     * @return
     */
    SysDicVO entity2Vo(SysDic entity);

    /**
     * 转成树形结构
     *
     * @param sysDic  字典
     * @param collect 字典项
     * @return
     * @date 2022/1/4 12:15 PM
     * @author liming
     */
    @Mapping(target = "child", source = "collect")
    SysDicTreeVo toDictTreeVo(SysDic sysDic, List<SysDicItemVO> collect);
}